<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<style>
	.form-element > label {
		float: left;
		width: 80px;
	}

	.form-field {
		margin-left: 100px;
	}

	.form-field-wrap ul {
		margin-bottom: 0;
	}
	
	.form textarea {
		width: 100%;
	}
</style>

<c:if test="${document.type == 2 && empty document.documentId}">
<form class="form">
	<div class="form-element">
		<label for="model"><spring:message code="model" /><span class="required"></span></label>
        
		<div class="form-field">
			<div class="form-field-wrap">
				<form:select path="modelList" id="documentModel">
					<form:option value="" label="Compor sem utilizar modelo" />
					<form:options items="${modelList}" itemValue="modelId" itemLabel="name" />
				</form:select>
			</div>
		</div>
        
		<div class="clear"></div>
	</div>
</form>
</c:if>

<form:form cssClass="form" method="post" action="save" commandName="document">
	<form:hidden path="appointment.appointmentId" id="documentAppointmentId" />
	<div class="form-element">
		<label for="name"><spring:message code="description" /><span class="required">*</span></label>
	    
		<div class="form-field">
			<div class="form-field-wrap form-textarea-wrap">
				<form:textarea path="description" rows="10" required="true" minlength="50" />
			</div>
		</div>
	    
		<div class="clear"></div>
	</div>

</form:form>

<script type="text/javascript">
	$("#documentModel").change(function() {
		if (this.value != '') {
			$.ajax({
				url: '<c:url value="/document/processModel.action" />',
				dataType: 'json',
				data: {
					modelId: $("#documentModel").val(),
					appointmentId: $("#appointmentId").val()
				},
				type: 'POST',
				success: function(response) {
					$("#description").val(response.message);
				}
			});
		}
	});
</script>